package net.baipeng.bp_aliyun_push;

import android.content.Context;

import com.alibaba.sdk.android.push.MessageReceiver;
import com.alibaba.sdk.android.push.notification.CPushMessage;

import java.util.Map;

import io.flutter.Log;

public class MyMessageReceiver extends MessageReceiver {

    public static final String TAG = "BpAliyunPushPlugin MyMessageReceiver";

    @Override
    public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
        Log.i(TAG, "onNotification, title: " + title + ", summary: " + summary + ", extraMap: " + extraMap);

        // TODO 角标
//        ShortcutBadger.applyCount(context, Integer.valueOf(extraMap.get("msg_unread")).intValue());

        /*
        FlutterPushNotification message = new FlutterPushNotification();
        message.title = title;
        message.summary = summary;
        message.extraMap = extraMap.toString();
        BpAliyunPushPlugin.sendPushNotification(message);
         */
    }

    @Override
    public void onMessage(Context context, CPushMessage cPushMessage) {
        Log.i(TAG, "onMessage, messageId: " + cPushMessage.getMessageId() + ", title: " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
        
        /*
        FlutterPushMessage message = new FlutterPushMessage();
        message.title = cPushMessage.getTitle();
        message.appId = cPushMessage.getAppId();
        message.messageId = cPushMessage.getMessageId();
        message.content = cPushMessage.getContent();
        message.traceInfo = cPushMessage.getTraceInfo();
        BpAliyunPushPlugin.sendPushMessage(message);
         */
    }

    @Override
    public void onNotificationOpened(Context context, String title, String summary, String extraMap) {
        Log.i(TAG, "onNotificationOpened, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
        
        FlutterPushNotification message = new FlutterPushNotification();
        message.title = title;
        message.summary = summary;
        message.extraMap = extraMap;
        BpAliyunPushPlugin.sendPushNotification(message);
    }

    @Override
    protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
        Log.i(TAG, "onNotificationClickedWithNoAction, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
    }

    @Override
    protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
        Log.i(TAG, "onNotificationReceivedInApp, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap + ", openType:" + openType + ", openActivity:" + openActivity + ", openUrl:" + openUrl);
    }

    @Override
    protected void onNotificationRemoved(Context context, String messageId) {
        Log.i(TAG, "onNotificationRemoved");
    }
}
